Title: SQL W3S (By-BKK) / 019 Avg
Tags: Obsidian_to_Anki

Q: What does the SQL AVG() function do?
A: It returns the average value of a numeric column

Q: How do you find the average price of products in SQL?
A: SELECT AVG(Price) FROM Products

Q: True/False: AVG() ignores NULL values in a column
A: True

Q: What is the syntax for AVG() with a condition?
A: SELECT AVG(column_name) FROM table_name WHERE condition

Q: How do you find the average price for products in category 1?
A: SELECT AVG(Price) FROM Products WHERE CategoryID = 1

Q: Reverse card:
SELECT AVG(Price) AS [average price] FROM Products
A: How do you name the AVG column as "average price"?

Q: How do you list products with a price higher than the average price?
A: SELECT * FROM Products WHERE Price > (SELECT AVG(Price) FROM Products)

Q: True/False: AVG() can be used with GROUP BY to find averages per group
A: True

Q: How do you find the average price per category in Products?
A: SELECT AVG(Price) AS AveragePrice, CategoryID FROM Products GROUP BY CategoryID

Q: Reverse card:
AVG() can only be used with numeric columns
A: Can you use AVG() with text columns?

Q: What is ignored by AVG() when calculating averages?
A: NULL values

Q: Reverse card:
NULL values are ignored by AVG()
A: Does AVG() include NULL values in its calculation?

Q: What is the purpose of AS in the AVG() function?
A: To give the result column a name or alias

Q: Write the SQL to find the average price for all products
A: SELECT AVG(Price) FROM Products

Q: Syntax for using AVG() on a column with WHERE clause
A: SELECT AVG(column_name) FROM table_name WHERE condition